/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.jesseenglish.swingftfy.extensions;

import java.net.URL;
import javax.swing.JCheckBox;

/**
 *
 * @author jesse
 */
public class FCheckBox extends JCheckBox {
    
    private String unmodifiedText = "";
    private String iconPath = null;
    
    @Override
    public void setText(String text) {
        this.unmodifiedText = text;
        render();
    }

    public String getUnmodifiedText() {
        return unmodifiedText;
    }
    
    public void setLabelIcon(URL url) {
        String path = url.toString();
        setLabelIcon(path);
    }
    
    public void setLabelIcon(String path) {
        this.iconPath = path;
        render();
    }
    
    private void render() {
        String label = unmodifiedText;
        if (iconPath != null) {
            label = "<html><table cellpadding=0><tr><td><img src=\"" + iconPath + "\"/></td><td width=\"3\"><td>" + unmodifiedText + "</td></tr></table></html>";
        }
        
        super.setText(label);
        
        validate();
        repaint();
    }
    
}
